/*
 *所有关于tb_project_reviewstandar_item类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*tb_project_reviewstandar_itemService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using Mapster;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using MYData.Core.EFDbContext;
using MYData.Core.Enums;
using MYData.Core.Utilities;
using MYData.Entity.DomainModels;
using MYData.Entity.DomainModels.ApiEntity;
using MYData.Entity.DomainModels.ApiEntity.detail;
using MYData.System.IRepositories;
using MYData.System.IServices;

namespace MYData.System.Services
{
    public partial class tb_project_reviewstandar_itemService : Itb_project_reviewstandar_itemService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly Itb_project_reviewstandar_itemRepository _repository;//访问数据库
        public readonly VOLContext _db;

        [ActivatorUtilitiesConstructor]
        public tb_project_reviewstandar_itemService(
            Itb_project_reviewstandar_itemRepository dbRepository,
            IHttpContextAccessor httpContextAccessor,
            VOLContext db
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _db = db;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }

        WebResponseContent webResponse = new WebResponseContent();
        /// <summary>
        /// 评审选项下拉显示
        /// </summary>
        /// <returns></returns>
        public async Task<WebResponseContent> SelectList()
        {
            var list = from x in _db.Set<tb_project_reviewstandar_item>().Where(x => x.isDelete == 0)
                       select new
                       {
                           standardselectionID = x.standardselectionID,
                           dselectionName = x.dselectionName,
                           totalPoints = x.totalPoints,
                           isDelete = x.isDelete
                       };

            return webResponse.OK("评审选项列表显示成功", list);
        }
        /// <summary>
        /// 评审选项显示
        /// </summary>
        /// <returns></returns>
        public async Task<WebResponseContent> GetList()
        {
            var list = _db.Set<tb_project_reviewstandar_item>().Where(x => x.isDelete == 0);

            return webResponse.OK("评审选项列表显示成功", list);
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <returns></returns>
        /// WJQ 2023/4/9
        public async Task<WebResponseContent> DeleteList(string id)
        {
            //根据id查询要删除的数据
            var groupInfo = _db.Set<tb_project_reviewstandar_item>().Find(id);
            //修改该字段
            groupInfo.isDelete = 1;
            _db.Update(groupInfo);
            //返回
            _db.SaveChanges();
            return webResponse.OK("删除成功");
        }
        /// <summary>
        /// 评审选项修改
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// WJQ 2023/4/9
        public async Task<WebResponseContent> UpdateInfo(reviewstandarDetail_Dto dto)
        {

            // 将输入Dto转换为领域模型
            // 把输入DTO转换成tb_project_reviewstandar_item实体
            var grouplist = dto.Adapt<tb_project_reviewstandar_item>();
            _db.Set<tb_project_reviewstandar_item>().Update(grouplist);
            //返回
            _db.SaveChanges();
            //返回提示信息
            return webResponse.OK("修改成功", true);

        }

    }
}
